/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*/

package com.chasekernan.hxnova.core.components;

import com.chasekernan.hxnova.core.components.ComponentSet;
import haxe.xml.Check;

/**
    Adds to the overal shield strength of the hull (or in the case of a few 
    special items, also adds to the overal strength of the hull as well).
**/
class Shield extends Component{
    
    public var strength(default, setStrength) : Int;
    private function setStrength(s : Int) : Int {if(s < 0) {throw "Strength must be >= 0";} else {strength = s;} return strength;}
    
    public var strengthArmor(default, setStrengthArmor) : Int;
    private function setStrengthArmor(s : Int) : Int {if(s < 0) {throw "StrengthArmor  must be >= 0";} else {strengthArmor = s;} return strengthArmor;}
    
    public function new(name : String, ?strength : Int, ?strengthArmor :Int) {
        super(name);
        setStrength(if (strength == null) 0 else strength);
        setStrengthArmor(if(strengthArmor == null) 0 else strengthArmor);
    }
    
    public static function writeToXml(s : Shield) : Xml {
        return Component.writeToXml(s);
    }
    
    public static function readFromXml(xml : Xml) : Shield {
        try {
            var s = new Shield("");
            //Check.checkNode(xml, s.getRules());
            s.generateFromComponentXml(xml, s);
            
            return s;
        } catch (e : Dynamic) {
            throw 'Bad xml file for shield: ' + e;
        }
    }
}